<?php
/**
 * Created by PhpStorm.
 * User: 技术员专用
 * Date: 2019/3/12
 * Time: 11:42
 */

$server = new Swoole\WebSocket\Server('0.0.0.0', 8812);
$server->set([
    'document_root' => '/www/wwwroot/live/data',
    'enable_static_handler' => true,
]);
$server->on('open', function (Swoole\WebSocket\Server $server,$request) {
    echo "server: handshake success with fd{$request->fd}".PHP_EOL;
});
$server->on('message', function (Swoole\WebSocket\Server $server,$frame) {
    echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}".PHP_EOL;
    $server->push($frame->fd, "this is server");
});
$server->on('close', function ($ser,$fd) {
    echo "client {$fd} closed".PHP_EOL;
});
$server->start();